/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.xsengine;

import com.xsengine.db.DBOperator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import static com.baga.util.Print.*;

/**
 *
 * @author baga
 */
public class Normalizer {
    private String[] allDoc;
    private DBOperator dbOp;
    private WeightContext wc;
    public Normalizer(String table) {
        dbOp = new DBOperator();
        wc = new WeightContext(table);
        allDoc = dbOp.getAllDoc();
    }

    public double getNormalizer() {
        double temp = 0.0;
        for(String s : allDoc) {
            double[] nilai = wc.getTfIdfNoHash(s, 2);
            for(double tmp : nilai) {
                tmp = Math.pow(tmp, 2);
                temp += tmp;
            }
        }
        return Math.sqrt(temp);
    }

//    public static double normalConst() {
//        DBOperator dbOp = new DBOperator();
//        String[] allContext = dbOp.getAllDoc();
//        double temp = 0.0;
//        WeightContext wc = new WeightContext();
//        for(String s : allContext) {
//            double[] tempDouble = wc.getTfIdfD(s);
//            for(double t : tempDouble) {
//                print("nilainya t " + t);
//                t = Math.pow(t, 2);
//                temp+= t;
//            }
//
//        }
//        return Math.sqrt(temp);
//    }

//    public static void main(String[] args) {
//        //print("nilainya " + Normalizer.normalConst());
//        Normalizer norm = new Normalizer();
//        print("nilainya jadi " + norm.getNormalizer());
//    }

}